/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import file from '@system.file'
import storage from '@system.storage';
import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index'

export default {
    data: {
        title: "",
    },
    onInit() {
        this.title = this.$t('strings.world');
    },
    test_storage_get: function () {
        console.info('testStorageGet START');
        storage.get({
            key: "storage_key",
            default: "123456",
            success: function (data) {
                console.info('LJT [storage.get] success: ' + data);
            },
            fail: function (data, code) {
                console.log('LJT [storage.get] fail, code: ' + code + ', data: ' + data);
            },
            complete: function () {
                console.log('LJT [storage.get] complete');
            }
        })
    },
    test_storage_get2: function () {
        console.info('testStorageGet2 START');
        storage.get({
            key: "storage_key2",
            success: function (data) {
                console.info('LJT [storage.get2] success: ' + data);
            },
            fail: function (data, code) {
                console.log('LJT [storage.get2] fail, code: ' + code + ', data: ' + data);
            },
            complete: function () {
                console.log('LJT [storage.get2] complete');
            }
        })
    },
    test_storage_get3: function () {
        console.info('testStorageGet3 START');
        storage.get({
            key: "s2",
            default: 'x'.repeat(129),
            success: function (data) {
                console.info('LJT [storage.get3] success: ' + data);
            },
            fail: function (data, code) {
                console.log('LJT [storage.get3] fail, code: ' + code + ', data: ' + data);
            },
            complete: function () {
                console.log('LJT [storage.get3] complete');
            }
        })
    },
    test_storage_set2: function () {
        console.info('testStorageSet START');
        storage.set({
            key: 'storage_key2',
            value: 'value2',
            success: function () {
                console.info('LJT [storage.set2] success');
            },
            fail: function (data, code) {
                console.info('LJT [storage.set2] fail, code: ' + code + ', data: ' + data);
            },
        });
    },
    test_storage_set3: function () {
        console.info('testStorageSet START');
        storage.set({
            key: 'storage_key3',
            value: 'value3',
            success: function () {
                console.info('LJT [storage.set3] success');
            },
            fail: function (data, code) {
                console.info('LJT [storage.set3] fail, code: ' + code + ', data: ' + data);
            },
        });
    },

    test_storage_set: function () {
        console.info('testStorageSet START');
        storage.set({
            key: 'storage_key',
            value: 'value1',
            complete: function(){
                console.info('LJT [storage.set] complete');
            },

            success: function(){
                console.info('LJT [storage.set] success');
            },

            fail: function (data, code) {
                console.info('LJT [storage.set] fail, code: ' + code + ', data: ' + data);
            },

        });
    },
    test_storage_clear: function () {
        console.info('testStorageClear START');
        storage.clear({
            success: function () {
                console.info('LJT [storage.clear] success');
            },
            fail: function (data, code) {
                console.info('LJT [storage.clear] fail, code: ' + code + ', data: ' + data);
            },
        })
    },
    test_storage_set_empty: function () {
        console.info('testStorageSet EMPTY START');
        storage.set({
            key: '',
            value: 'value3',
            success: function () {
                console.info('LJT [storage.setEmpty] success');
            },
            fail: function (data, code) {
                console.info('LJT [storage.setEmpty] fail, code: ' + code + ', data: ' + data);
            },
        });
    },
    test_storage_set_maxKey: function () {
        console.info('testStorageSet MAXKEY START');
        storage.set({
            key: 'x'.repeat(33),
            value: 'max',
            success: function () {
                console.info('LJT [storage.setMaxKey] success');
            },
            fail: function (data, code) {
                console.info('LJT [storage.setMaxKey] fail, code: ' + code + ', data: ' + data);
            },
        });
    },
    test_storage_set_maxValue: function () {
        console.info('testStorageSet MAXVALUE START');
        storage.set({
            key: 'max',
            value: 'x'.repeat(129),
            success: function () {
                console.info('LJT [storage.setMaxValue] success');
            },
            fail: function (data, code) {
                console.info('LJT [storage.setMaxValue] fail, code: ' + code + ', data: ' + data);
            },
        });
    },
    test_storage_delete: function () {
        console.info('testStorageDelete START');
        storage.delete({
            key: "storage_key2",
            success: function () {
                console.info('LJT [storage.delete] success');
            },
            fail: function (data, code) {
                console.info('LJT [storage.delete] fail, code: ' + code + ', data: ' + data);
            },
        })
    },
    onclick: function () {
    },
    onShow: function () {
        console.info('RDB_TEST:onShow')
        const core = Core.getInstance()
        const expectExtend = new ExpectExtend({
            'id': 'extend'
        })
        const reportExtend = new ReportExtend(file)
        core.addService('expect', expectExtend)
        core.addService('report', reportExtend)
        core.init()

        const configService = core.getDefaultService('config')
        configService.setConfig(this)

        require('../../../test/List.test')
        core.execute()

        this.title = 'RDB_TEST:onShow finished.'
        console.info('RDB_TEST:onShow finished.')
    }
}

